package views;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import controllers.GameOverController;
import controllers.LevelController;

public class GameOverView extends JFrame{

	private static final long serialVersionUID = -5186796857893978341L;

	//Atributos
		private int windowWidth;
		private int windowHeight;
		private int titleHeight;
		
		private Image titleBg;
		private JPanel centerPanel;
		private JPanel northPanel;
		private JLabel lbGameTitle;
		private JButton btNewGame;
		private String btTextNewGame;
		private JButton btExit;
		private String btTextExit;
		private String endGameText;
		
		//Construtor
		public GameOverView(String endGameText, String btTextNewGame, boolean isNewGame)
		{
			if(isNewGame)
				LevelController.setLevel(0);
			this.endGameText = endGameText;
			this.btTextNewGame = btTextNewGame;
			windowWidth = 300;
			windowHeight = 300;
			titleHeight = 100;
			btTextExit = "Sair";
			lbGameTitle = new JLabel("Tower Defense");

			//Layout
			this.setLayout(new BorderLayout());
			centerPanel = new JPanel();
			northPanel = new JPanel();
			this.setVisible(true);
			//North
			titleBg = createImage(windowWidth, titleHeight);
			JLabel lbTitle = new JLabel(new ImageIcon(titleBg));
			northPanel.add(lbTitle);
			northPanel.add(lbGameTitle);
			//Center
			btNewGame = new JButton();
			btNewGame.setText(btTextNewGame);
			btExit = new JButton();
			btExit.setText(btTextExit);
			
			centerPanel.setLayout(new GridLayout(3,1));
			centerPanel.add(new JLabel(endGameText));
			centerPanel.add(btNewGame);
			centerPanel.add(btExit);
			
			this.add("North", northPanel);
			this.add("Center", centerPanel);
			this.pack();
			this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
			
		}
		
		//Getters
		public String getBtTextNewGame(){
			return this.btTextNewGame;
		}
		
		public String getBtTextExit(){
			return this.btTextExit;
		}
		
		//Setters
		public void setController(GameOverController goc){
	        this.addWindowListener(goc);
	        this.btNewGame.addActionListener(goc);
	        this.btExit.addActionListener(goc);
	    }
		
}
